package com.nari.ies.ne.nw.server.service.fileScore.impl;

import com.nari.ies.ne.nw.server.entity.PvFileScoreEntity;
import com.nari.ies.ne.nw.server.entity.WindFileScoreEntity;
import com.nari.ies.ne.nw.server.mapper.FileScoreMapper;
import com.nari.ies.ne.nw.server.service.fileScore.IFileScoreService;
import com.nari.ies.ne.nw.server.service.fileScore.ITJXXFileScoreService;
import com.nari.ies.ne.nw.server.util.DataUtil;
import com.nari.ies.ne.nw.server.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TJXXFileScoreServiceImpl implements ITJXXFileScoreService {
    @Autowired
    private IFileScoreService fileScoreService;
    @Autowired
    private FileScoreMapper fileScoreMapper;
    @Override
    public WindFileScoreEntity FDTJXXFileScore(WindFileScoreEntity windFileScoreEntity) {
        String plantId = windFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = windFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "TJXX";
        String plantType = "FD";
        String tableName = "HISDB.NW_NE_FILE_DATACHECK_FD_TJXX";

        //上送文件数量
        int TJXXNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float TJXXFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float TJXXRate = 0;
        //文件上送率
        float TJXXSendRate = 0;
        //文件得分
        float TJXXScore = 0;
        //文件合格率
        float TJXXQualifiedRate = 0;

        if (TJXXNum > 0) {
            //文件上送率
            TJXXSendRate = 100;
            TJXXRate = (float) TJXXNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            TJXXScore = fileDataScore;
            //文件合格率
            TJXXQualifiedRate = TJXXScore / TJXXFullScore * 100;
        }else {
            TJXXRate=0;
            TJXXScore=0;
            TJXXSendRate=0;
            TJXXQualifiedRate=0;
        }
        windFileScoreEntity.setTJXXNum(TJXXNum);
        windFileScoreEntity.setTJXXRate(TJXXRate);
        windFileScoreEntity.setTJXXScore(TJXXScore);
        windFileScoreEntity.setTJXXFullScore(TJXXFullScore);
        windFileScoreEntity.setTJXXSendRate(TJXXSendRate);
        windFileScoreEntity.setTJXXQualifiedRate(TJXXQualifiedRate);

        return windFileScoreEntity;
    }

    @Override
    public PvFileScoreEntity GFTJXXFileScore(PvFileScoreEntity pvFileScoreEntity) {
        String plantId = pvFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = pvFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "TJXX";
        String plantType = "GF";
        String tableName="HISDB.NW_NE_FILE_DATACHECK_GF_TJXX";

        //上送文件数量
        int TJXXNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float TJXXFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float TJXXRate = 0;
        //文件上送率
        float TJXXSendRate = 0;
        //文件得分
        float TJXXScore = 0;
        //文件合格率
        float TJXXQualifiedRate = 0;

        if (TJXXNum > 0) {
            //文件上送率
            TJXXSendRate = 100;
            TJXXRate = (float) TJXXNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            TJXXScore = fileDataScore;
            //文件合格率
            TJXXQualifiedRate = TJXXScore / TJXXFullScore * 100;
        }else {
            TJXXRate=0;
            TJXXScore=0;
            TJXXSendRate=0;
            TJXXQualifiedRate=0;
        }
        pvFileScoreEntity.setTJXXNum(TJXXNum);
        pvFileScoreEntity.setTJXXRate(TJXXRate);
        pvFileScoreEntity.setTJXXScore(TJXXScore);
        pvFileScoreEntity.setTJXXFullScore(TJXXFullScore);
        pvFileScoreEntity.setTJXXQualifiedRate(TJXXSendRate);
        pvFileScoreEntity.setTJXXSendRate(TJXXQualifiedRate);
        return pvFileScoreEntity;
    }


}
